package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.VisitDto;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.VisitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {

    @Autowired
    private ReservationService reservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledReservationCount() {
        Integer count = reservationService.countCancelReservation();
        return success(count);
    }

    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult addCancelledReservation(@RequestBody VisitDto visitDto) {
        reservationService.addReservation(visitDto);
        return success();
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult<List<Map<String, Object>>> countReservationByTime(Long time) {
        List<Map<String, Object>> countReservationMap = reservationService.countReservationByTime(time);
        return success(countReservationMap);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public ResponseResult<PageResponse<VisitVo>> pageReservations(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,
            Integer status) {
        PageResponse<VisitVo> pageResponse = reservationService.pageReservations(pageNum, pageSize, status);
        return success(pageResponse);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult updateReservationStatus(@PathVariable("id") Long id) {
        reservationService.updateReservationStatus(id);
        return success();
    }
}